package com.hkbigdata.transfer;

import org.apache.flink.api.java.functions.KeySelector;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.KeyedStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author liuanbo
 * @creat 2024-04-12-17:28
 * @see 2194550857@qq.com
 */
public class Flink08_TransForm_Aggregate_Anonymous {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        DataStreamSource<Integer> integerDataStreamSource = env.fromElements(1, 7, 8, 5, 6);
        KeyedStream<Integer, String> integerStringKeyedStream = integerDataStreamSource.keyBy(new KeySelector<Integer, String>() {
            @Override
            public String getKey(Integer value) throws Exception {
                return value % 2 == 0 ? "偶数" : "奇数";
            }
        });

        integerStringKeyedStream.sum(0).print("sum");
        integerStringKeyedStream.max(0).print("max");
        integerStringKeyedStream.min(0).print("min");


        env.execute();


    }
}
